package com.ruoyi.leads.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.leads.domain.Leads;
import com.ruoyi.leads.service.ILeadsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索管理Controller
 * 
 * @author suoge
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/leads/leads")
public class LeadsController extends BaseController
{
    @Autowired
    private ILeadsService leadsService;

    /**
     * 查询线索管理列表
     */
    @PreAuthorize("@ss.hasPermi('leads:leads:list')")
    @GetMapping("/list")
    public TableDataInfo list(Leads leads)
    {
        startPage();
        List<Leads> list = leadsService.selectLeadsList(leads);
        return getDataTable(list);
    }

    /**
     * 导出线索管理列表
     */
    @PreAuthorize("@ss.hasPermi('leads:leads:export')")
    @Log(title = "线索管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Leads leads)
    {
        List<Leads> list = leadsService.selectLeadsList(leads);
        ExcelUtil<Leads> util = new ExcelUtil<Leads>(Leads.class);
        util.exportExcel(response, list, "线索管理数据");
    }

    /**
     * 获取线索管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('leads:leads:query')")
    @GetMapping(value = "/{leadId}")
    public AjaxResult getInfo(@PathVariable("leadId") Long leadId)
    {
        return success(leadsService.selectLeadsByLeadId(leadId));
    }

    /**
     * 新增线索管理
     */
    @PreAuthorize("@ss.hasPermi('leads:leads:add')")
    @Log(title = "线索管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Leads leads)
    {
        return toAjax(leadsService.insertLeads(leads));
    }

    /**
     * 修改线索管理
     */
    @PreAuthorize("@ss.hasPermi('leads:leads:edit')")
    @Log(title = "线索管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Leads leads)
    {
        return toAjax(leadsService.updateLeads(leads));
    }

    /**
     * 删除线索管理
     */
    @PreAuthorize("@ss.hasPermi('leads:leads:remove')")
    @Log(title = "线索管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leadIds}")
    public AjaxResult remove(@PathVariable Long[] leadIds)
    {
        return toAjax(leadsService.deleteLeadsByLeadIds(leadIds));
    }
}
